/*********************************************************************
* File: ICommunication.h
*
* Supports agent communication.
*********************************************************************/
#pragma once

#include "../globals.h"
#include "IRadar.h"

namespace agents{namespace interfaces{
	/**
	* \class ICommunication
	* \brief Supports agent communication.
	*
	* Supports predefined radio-based and generic chat-based communication.
	*
	* \author Instituto Superior Tecnico de Lisboa, Portugal
	* \author Technical University of Lisbon, Portugal
	* 
	* \author Agentes Autonomos e Sistemas Multiagente
	* \author Autonomous Agents and Multiagent Systems
	* 
	* \version	1.0
	* \date		2006/2007
	**/
	class ICommunication
	{
	public:	
		//=====================================================================
		// Enumerations
		//=====================================================================
		/** 
		* \brief Chat messages. 
		**/
		class SayMessages{
		public:
			/** 
			* \brief Chat messages. 
			**/
			enum Enumeration
			{
				/** All chat message. **/
				sayMsg,
				/** Team chat message. **/
				sayTeamMsg,
				/** Dead chat message. **/
				sayDeadMsg
			};
		};

		/** 
		* \brief Radio messages 
		**/
		class RadioMessages{
		public:
			enum Enumeration
			{
				/** Cover Me. **/
				coverMe			= 1,
				/** You take the point. **/
				youTakePoint		= 2, 
				/** Hold position. **/
				holdPosition		= 3,
				/** Regroup team. **/
				regroupTeam		= 4,
				/** Follow me. **/
				followMe			= 5,
				/** Taking fire. **/
				takingFire		= 6,

				/** Go, go, go. **/
				goGoGo			= 11,
				/** Fall back. **/
				fallBack			= 12,
				/** Stick together. **/
				stickTogether	= 13,
				/** Get in position. **/
				getInPosition	= 14,
				/** Storm the front. **/
				stormTheFront	= 15,
				/** Report team. **/
				reportTeam		= 16,

				/** Affirmative. **/
				affirmative		= 21,
				/** Enemy spotted. **/
				enemySpotted		= 22, 
				/** Need backup. **/
				needBackup		= 23, 
				/** Sector clear. **/
				sectorClear		= 24, 
				/** I'm in position. **/
				imInPosition		= 25,
				/** Reporting in. **/
				reportingIn		= 26, 
				/** She's gonna blow. **/
				shesGonnaBlow	= 27, 
				/** Negative. **/
				negative			= 28, 
				/** Enemy down. **/
				enemyDown		= 29, 

				/** Null. **/
				null				= 0
			};
		};

		//=====================================================================
		// Classes
		//=====================================================================
		/**
		* \brief A message sender.
		**/
		class MessageSender
		{
		public:
			/**
			* \brief The sender's name.
			**/
			char name[AGENT_NAME_MAX_LENGTH];
			/**
			* \brief The sender's location in the radar.
			**/
			IRadar::RadarUnit radarUnit;
		};

		/**
		* \brief A chat message record.
		**/
		class MessageRecord{
		public:
			/**
			* \brief The class constructor.
			**/
			MessageRecord(){
				msg = NULL;
			}
			/**
			* \brief The class destructor.
			**/
			~MessageRecord(){
				if(msg != NULL)
					free(msg);
			}

			/** 
			* \brief The message.
			**/
			char* msg;
			/** 
			* \brief The sender's entity.
			**/
			MessageSender sender;
			/** 
			* \brief Time message was sent.
			**/
			float timeStamp;
		};

		/**
		* \brief A radio message record
		**/
		class RadioMessageRecord{
		public:
			/** 
			* \brief The message. 
			**/
			RadioMessages::Enumeration msg;
			/** 
			* \brief The sender's entity. 
			**/
			MessageSender sender;
			/** 
			* \brief Time message was sent.
			**/
			float timeStamp;
		};

		//=====================================================================
		// Function prototypes
		//=====================================================================
		/**
		* \brief Sends a message to all players.
		*
		* Uses the CS chat feature. The platform automatically appends a 
		* prefix to the message to identify the sender as so: <id>:<msg>.
		*
		* \param[in] msg The message.
		**/
		virtual void sayText(const char *msg) = 0;
		/**
		* \brief Sends a message to all team players.
		*
		* Uses the CS team chat feature. The platform automatically appends a 
		* prefix to the message to identify the sender as so: <id>:<msg>.
		*
		* \param[in] msg The message.
		**/
		virtual void teamSayText(const char *msg) = 0;
		/**
		* \brief Checks whether a chat message has arrived.
		*
		* \param[in] sayMsgType The chat message type.
		* \param[out] record The message record.
		* \return Whether any message was available.
		**/
		virtual bool receiveMsg(SayMessages::Enumeration sayMsgType, MessageRecord* record) = 0;
		/**
		* \brief Sends a radio message to all team players.
		*
		* \param[in] msg The radio message.
		**/
		virtual void sendRadioMessage(RadioMessages::Enumeration msg) = 0;
		/**
		* \brief Checks whether a radio message has arrived.
		*
		* \param[out] record The message record.
		* \return Whether any message was available.
		**/
		virtual bool receiveRadioMsg(RadioMessageRecord* record) = 0;
	};
}}
